ALMaSS  1.0
The Animal, Landscape and Man Simulation System
PesticideMap Class Reference

#include <pesticide.h>

Public Member Functions

 PesticideMap (int a_startyear, int a_noyears, int a_cellsize, Landscape *a_landscape, RasterMap *a_land, bool a_typeofmap)
 
 ~PesticideMap ()
 
bool DumpPMap (vector< double > *a_map)
 
bool DumpPMapI ()
 
bool DumpPMapH ()
 
bool DumpPMapF ()
 
void Spray (LE *a_element_sprayed, TTypesOfPesticideCategory a_type)
 

Protected Attributes

vector< double > * m_pmap_insecticides
 insecticide map data More...
 
vector< double > * m_pmap_fungicides
 herbicide map data More...
 
vector< double > * m_pmap_herbicides
 fungicide map data More...
 
int m_startyear
 first simultion year to record More...
 
int m_endyear
 last year of data to record More...
 
int m_cellsize
 the size of the cell for pesticide data in m More...
 
int m_pmap_width
 based on cellsize the width of the map More...
 
int m_pmap_height
 based on cellsize the height of the map More...
 
bool m_typeofmap
 true if using test pesticide, false for general pesticides More...
 
Landscapem_OurLandscape
 pointer to the landscape
More...
 
RasterMapm_Rastermap
 pointer to the landscape map More...
 

Constructor & Destructor Documentation

◆ PesticideMap()

PesticideMap::PesticideMap ( int  a_startyear,
int  a_noyears,
int  a_cellsize,
Landscape a_landscape,
RasterMap a_land,
bool  a_typeofmap 
)
770 {
771  m_typeofmap = a_typeofmap;
772  m_startyear = a_startyear;
773  m_endyear = a_startyear + a_noyears;
774  m_cellsize = a_cellsize;
775  m_OurLandscape = a_landscape;
776  m_Rastermap = a_land;
779 
780  // Need to create the grid to fill. This grid is always used.
781  m_pmap_insecticides = new vector<double>;
783  fill(m_pmap_insecticides->begin(), m_pmap_insecticides->end(), 0);
784  ofstream * m_PMap;
785  m_PMap = new ofstream("ALMaSS_InsecticideMap.txt", ios::out);
786  (*m_PMap) << "Years" << ' ' << a_noyears << ' ' << "Height" << ' ' << m_pmap_height << ' ' << "Width" << ' ' << m_pmap_width << ' ' << endl;
787  m_PMap->close();
788  // These two grids are used only if we want all three types recoreded.
789  if (!m_typeofmap)
790  {
791  // We need all three in this case
792  m_pmap_fungicides = new vector<double>;
794  fill(m_pmap_fungicides->begin(), m_pmap_fungicides->end(), 0);
795  m_PMap = new ofstream("ALMaSS_FungicideMap.txt", ios::out);
796  (*m_PMap) << "Years" << ' ' << a_noyears << ' ' << "Height" << ' ' << m_pmap_height << ' ' << "Width" << ' ' << m_pmap_width << ' ' << endl;
797  m_PMap->close();
798  m_pmap_herbicides = new vector<double>;
800  fill(m_pmap_herbicides->begin(), m_pmap_herbicides->end(), 0);
801  m_PMap = new ofstream("ALMaSS_HerbicideMap.txt", ios::out);
802  (*m_PMap) << "Years" << ' ' << a_noyears << ' ' << "Height" << ' ' << m_pmap_height << ' ' << "Width" << ' ' << m_pmap_width << ' ' << endl;
803  m_PMap->close();
804  }
805  else
806  {
807  m_pmap_fungicides = NULL;
808  m_pmap_herbicides = NULL;
809  }
810 }
int SupplySimAreaHeight(void)
Definition: landscape.h:1637
int SupplySimAreaWidth(void)
Definition: landscape.h:1632
int m_cellsize
the size of the cell for pesticide data in m
Definition: pesticide.h:387
RasterMap * m_Rastermap
pointer to the landscape map
Definition: pesticide.h:397
int m_endyear
last year of data to record
Definition: pesticide.h:385
int m_pmap_height
based on cellsize the height of the map
Definition: pesticide.h:391
vector< double > * m_pmap_herbicides
fungicide map data
Definition: pesticide.h:381
int m_startyear
first simultion year to record
Definition: pesticide.h:383
bool m_typeofmap
true if using test pesticide, false for general pesticides
Definition: pesticide.h:393
Landscape * m_OurLandscape
pointer to the landscape
Definition: pesticide.h:395
int m_pmap_width
based on cellsize the width of the map
Definition: pesticide.h:389
vector< double > * m_pmap_insecticides
insecticide map data
Definition: pesticide.h:377
vector< double > * m_pmap_fungicides
herbicide map data
Definition: pesticide.h:379

◆ ~PesticideMap()

PesticideMap::~PesticideMap ( )
813 {
814  delete m_pmap_insecticides;
815  if (!m_typeofmap)
816  {
817  // We need all three in this case
818  delete m_pmap_fungicides;
819  delete m_pmap_herbicides;
820 
821  }
822 }

Member Function Documentation

◆ DumpPMap()

bool PesticideMap::DumpPMap ( vector< double > *  a_map)
825 {
826  string fname;
827  if (a_map == m_pmap_insecticides) fname = "ALMaSS_InsecticideMap.txt";
828  else if (a_map == m_pmap_fungicides) fname = "ALMaSS_FungicideMap.txt";
829  else fname = "ALMaSS_HerbicideMap.txt";
830  {
831  ofstream* m_PMap = new ofstream(fname.c_str(), ios::app);
832  if (!(*m_PMap).is_open())
833  {
834  g_msg->Warn(WARN_FILE, "PesticideMap::DumpMap Unable to open file for append: ", fname.c_str());
835  exit(1);
836  }
837  // File is OK, save the map
838  (*m_PMap) << "Year " << g_date->GetYear() << "Month " << g_date->GetMonth() << endl;
839  for (int y = 0; y < m_pmap_height; y++)
840  {
841  for (int x = 0; x < m_pmap_width; x++)
842  {
843  (*m_PMap) << (*a_map)[y*m_pmap_width + x] << ' ';
844  }
845  }
846  (*m_PMap) << endl;
847  m_PMap->close();
848  }
849  fill(a_map->begin(), a_map->end(), 0);
850  return true;
851 }
class Calendar * g_date
Definition: calendar.cpp:38
int GetMonth(void)
Definition: calendar.h:69
int GetYear(void)
Definition: calendar.h:67
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:59
class MapErrorMsg * g_msg
This pointer provides access the to the internal ALMaSS error message system.
Definition: maperrormsg.cpp:41
@ WARN_FILE
Definition: maperrormsg.h:37

References g_date, g_msg, Calendar::GetMonth(), Calendar::GetYear(), MapErrorMsg::Warn(), and WARN_FILE.

Referenced by DumpPMapF(), DumpPMapH(), and DumpPMapI().

◆ DumpPMapF()

bool PesticideMap::DumpPMapF ( )
inline
405 { return DumpPMap(m_pmap_fungicides); }
bool DumpPMap(vector< double > *a_map)
Definition: pesticide.cpp:824

References DumpPMap(), and m_pmap_fungicides.

◆ DumpPMapH()

bool PesticideMap::DumpPMapH ( )
inline
404 { return DumpPMap(m_pmap_herbicides); }

References DumpPMap(), and m_pmap_herbicides.

◆ DumpPMapI()

bool PesticideMap::DumpPMapI ( )
inline
403 { return DumpPMap(m_pmap_insecticides); }

References DumpPMap(), and m_pmap_insecticides.

◆ Spray()

void PesticideMap::Spray ( LE a_element_sprayed,
TTypesOfPesticideCategory  a_type 
)

This records a 1 in the map for every m2 where pesticide is applied. This does not record drift.

Going through the whole landscape is very slow and unnecessary for small polygons. Since our polygons do not extend beyond the edge of the map ie do not wrap round, then we only need a measure of minx, maxx, miny, maxy. This is set up at the start of the simulation.

This method first determines what type of pesticide and selects the correct map to record on.

855 {
867  vector<double>* ourmap = m_pmap_insecticides; ;
868  if (a_type == fungicide) ourmap = m_pmap_fungicides;
869  else if (a_type == herbicide) ourmap = m_pmap_herbicides;
870  int l_large_map_index = a_element_sprayed->GetMapIndex();
871  int minx = a_element_sprayed->GetMinX();
872  int miny = a_element_sprayed->GetMinY();
873  int maxx = a_element_sprayed->GetMaxX();
874  int maxy = a_element_sprayed->GetMaxY();
875  for (int y = miny; y <= maxy; y++) {
876  for (int x = minx; x <= maxx; x++) {
877  if (m_Rastermap->Get(x, y) == l_large_map_index)
878  {
879  // Add one m spray value of 1.0 per m
880  (*ourmap)[(x/m_cellsize)+(y/m_cellsize)*m_pmap_width]++;
881  }
882  }
883  }
884 }
int GetMinY(void)
Definition: elements.h:336
int GetMinX(void)
Definition: elements.h:335
int GetMaxX(void)
Definition: elements.h:333
int GetMaxY(void)
Definition: elements.h:334
int GetMapIndex(void)
Definition: elements.h:190
int Get(int a_x, int a_y)
Definition: rastermap.h:81
@ fungicide
Definition: landscape.h:63
@ herbicide
Definition: landscape.h:63

References fungicide, LE::GetMapIndex(), LE::GetMaxX(), LE::GetMaxY(), LE::GetMinX(), LE::GetMinY(), and herbicide.

Member Data Documentation

◆ m_cellsize

int PesticideMap::m_cellsize
protected

the size of the cell for pesticide data in m

◆ m_endyear

int PesticideMap::m_endyear
protected

last year of data to record

◆ m_OurLandscape

Landscape* PesticideMap::m_OurLandscape
protected

pointer to the landscape

◆ m_pmap_fungicides

vector<double>* PesticideMap::m_pmap_fungicides
protected

herbicide map data

Referenced by DumpPMapF().

◆ m_pmap_height

int PesticideMap::m_pmap_height
protected

based on cellsize the height of the map

◆ m_pmap_herbicides

vector<double>* PesticideMap::m_pmap_herbicides
protected

fungicide map data

Referenced by DumpPMapH().

◆ m_pmap_insecticides

vector<double>* PesticideMap::m_pmap_insecticides
protected

insecticide map data

PesticideMap is a class for handling pesticide mapping output. This can be used to sum up pesticide concentrations over time. It works currently for general pesticides split into insecticides, herbicides, and fungicides, but also for the primary test pesticide if one is being used.

Referenced by DumpPMapI().

◆ m_pmap_width

int PesticideMap::m_pmap_width
protected

based on cellsize the width of the map

◆ m_Rastermap

RasterMap* PesticideMap::m_Rastermap
protected

pointer to the landscape map

◆ m_startyear

int PesticideMap::m_startyear
protected

first simultion year to record

◆ m_typeofmap

bool PesticideMap::m_typeofmap
protected

true if using test pesticide, false for general pesticides


The documentation for this class was generated from the following files: